﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebEnableServices.aspx.cs" Inherits="Skynet.WebSite.Demos.WebEnableServices" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <script type="text/javascript">
        function BeginAuthenticateUser() {
            var uid;
            var pwd;
            var isPersistent;
            uid = document.getElementById('TextBox1').value;
            pwd = document.getElementById('TextBox2').value;
            isPersistent = document.getElementById('CheckBox1').checked;
            Sys.Services.AuthenticationService.login(uid, pwd, isPersistent, null, null, EndAuthenticateUser, OnError, uid);
            return false;
        }
        function EndAuthenticateUser(result, userContext, methodName) {
            if (result) {
                document.location = "ViewInfo.aspx";
            }
            else {
                alert("Unable to login! Please check user id and password!!");
            }
        }
        function OnError(result, userContext, methodName) {
            alert(result.get_message());
        }
        function BeginProfileLoad() {
            
            Sys.Services.ProfileService.load (null, EndProfileLoad, OnProfileFailed, null);            
            return false;
        }
        function OnProfileFailed() {
            alert("Profile failed");
        }
        function EndProfileLoad(numProperties, userContext, methodName) {
            document.getElementById('TextProfile').value = Sys.Services.ProfileService.properties.Bgcolor;
        }
        function BeginSaveProfile() {
            Sys.Services.ProfileService.properties.Bgcolor = document.getElementById('TextProfile').value;            
            Sys.Services.ProfileService.save(null, EndSaveProfile, OnProfileFailed, null);
            return false;
        }
        function EndSaveProfile(numProperties, userContext, methodName) {
            alert('Your profile is saved successfully!');
        }
    </script>
    <div>
        <table>
            <tr>
                <td>Username</td>
                <td> <asp:TextBox ID="TextBox1" runat=server></asp:TextBox> </td>
            </tr>
            <tr>
                <td>Username</td>
                <td> <asp:TextBox ID="TextBox2" runat=server></asp:TextBox> </td>
            </tr>
            <tr>
            <td>
                Remember me
            </td>
            <td>
                <asp:CheckBox ID="CheckBox1" runat="server" />
            </td>

            </tr>
            <tr>
            <td></td>
            <td>
                <input id="Button1" type="button" value="button" onclick="return BeginAuthenticateUser();" />
            </td>
            </tr>
            <tr>
                <td>Profile</td>
                <td> 
                    <input id="TextProfile" type="text" /></td>
            </tr>
            <tr>
                <td>
                    <input id="Button2" type="button" value="button" onclick="return BeginProfileLoad();" />
                </td>
                <td>
                    <input id="Button3" type="button" value="button"  onclick="return BeginSaveProfile();"/>
                </td>
            </tr>
        </table>

    
    </div>
    </form>
</body>
</html>
